/*
 * @Author: liuYang codkly@gmail.com
 * @Date: 2022-12-05 16:25:57
 * @LastEditors: liuYang codkly@gmail.com
 * @LastEditTime: 2022-12-08 11:27:02
 * @FilePath: \coding\nest\blog_alpha\src\app.module.ts
 * @Description:
 * 暂无备注
 */
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_INTERCEPTOR } from '@nestjs/core';

import { RequestInterceptor } from './core/interceptor/transform/transform.interceptor';
import configDefault from '../config/config.default';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { RoleModule } from './role/role.module';
import { PermissionModule } from './permission/permission.module';
import { UserinfoModule } from './userinfo/userinfo.module';
import { ArticleModule } from './article/article.module';
import { TagModule } from './tag/tag.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [configDefault],
    }),
    // TypeOrm模块
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('mysql.host'),
        port: +configService.get('mysql.pord'),
        username: configService.get('mysql.username'),
        password: configService.get('mysql.password'),
        database: configService.get('mysql.database'),
        synchronize: configService.get('mysql.synchronize'),
        autoLoadEntities: true,
        keepConnectionAlive: true,
      }),
    }),
    UserModule,
    RoleModule,
    PermissionModule,
    UserinfoModule,
    ArticleModule,
    TagModule,
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_INTERCEPTOR,
      useClass: RequestInterceptor,
    },
  ],
})
export class AppModule {}
